package com.herui.ota.service.iml;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.herui.ota.dao.mysql.DeviceXinpianEventMapper;
import com.herui.ota.entity.Device;
import com.herui.ota.entity.DeviceXinpianEvent;
import com.herui.ota.enums.ResponseEnum;
import com.herui.ota.exception.ServiceException;
import com.herui.ota.pojo.form.DeviceXinpianEventForm;
import com.herui.ota.service.DeviceService;
import com.herui.ota.service.DeviceXinpianEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * author name: amanda.shan
 * create time: 2024-07-01 09:43:45
 */ 
@Service
public class DeviceXinpianEventServiceIml extends BaseService<DeviceXinpianEventMapper, DeviceXinpianEvent> implements DeviceXinpianEventService{

	@Autowired
	private DeviceService deviceService;

	@Autowired
	@Override
	public void setBaseMapper(DeviceXinpianEventMapper baseMapper) {
		super.setBaseMapper(baseMapper);
	}

	@Override
	public void save(DeviceXinpianEventForm form) {
		Device device = deviceService.getOne(new QueryWrapper<Device>().eq("blu_name", form.getBluName()));
		if (device == null){
			throw new ServiceException(ResponseEnum.DEVICE_NOT_EXIST);
		}
		DeviceXinpianEvent deviceXinpianEvent = new DeviceXinpianEvent();
		deviceXinpianEvent.setDeviceId(device.getId());
		deviceXinpianEvent.setCode(form.getCode());
		deviceXinpianEvent.setStartTime(form.getStartTime());
		deviceXinpianEvent.setEndTime(form.getEndTime());
		deviceXinpianEvent.setVersion(form.getVersion());
		super.save(deviceXinpianEvent);
	}
}

